This example implements a wrapper. Wrappers are views which contain other views but don't have their own models. In particular, a wrapper may have the same size as the view(s) that it wraps. In this way, it can combine its own functionality with that of the wrapped view(s).
For example
- a debugging wrapper may list the messages received by the wrapped view into the log
- a background wrapper may add a background color, over which its wrapped view is drawn (which typically has no background color, i.e. which has a transparent background)
- a layer wrapper may contain several layered views, e.g. a graph view overlaid by a caption view
- a terminal wrapper which contains a terminal session and wraps a standard text view
- a bundling wrapper which filters out controller messages, such that the wrapped view becomes read-only
etc., the sky's the limit! Wrappers demonstrate the power of composition, i.e. how functionality of different objects can be combined in a very simple manner, without having to use complex language mechanisms such as (multiple) inheritance.
Our example wrapper simply echoes every key typed in to the log.
ObxWrappers.Wrap (* select view (singleton) before calling this command *)
ObxWrappers.Unwrap (* select view (singleton) before calling this command *)
(* <== for example, select this view *)
and then type in some characters, and see what happens in the log.